package com.nut.article.api.biz;

import com.nut.article.common.Result;
import com.nut.article.entity.Tag;
import com.nut.article.service.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping(value = "list")
    public List<Tag> list() {
        return tagService.list();
    }

    @GetMapping(value = "/{id}")
    public Result<Tag> detail(@PathVariable Integer id) {
        return tagService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody Tag tag) {
        return tagService.add(tag);
    }

    @PutMapping
    public Result update(@RequestBody Tag tag) {
        return tagService.updateById(tag);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return tagService.deleteByIds(ids);
    }

}
